<!-- eslint-disable vue/no-template-key -->
<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wiz
 * @Date: 2023-04-30 12:22:02
 * @LastEditors: swc
 * @LastEditTime: 2024-12-12 14:18:27
-->
<template>
  <div id="app">
    <router-view />
    <div v-for="(modal, idx) of modalList" :key="idx">
      <component
        :is="modal.name"
        v-bind="{ config: modal.params, id: modal.moduleID }"
      />
    </div>
  </div>
</template>

<script lang="ts">
import { T_srv, Tsrv, vue } from '@/services';

@T_srv.comp
export default class app extends vue {
  public modalList: any = [];

  mounted() {
    // 增加组件
    this.$bus.$on(
      'addModal',
      (moduleName: string, params: any = null, moduleID: number) => {
        this.modalList.push({
          name: moduleName,
          params,
          moduleID
        });
      }
    );
    // 移除组件
    this.$bus.$on('removeModal', (moduleID: number) => {
      Tsrv.utils.remove(this.modalList, el => el.moduleID === moduleID);
    });
  }

  destroyed() {
    this.$bus.$off('removeModal');
    this.$bus.$off('addModal');
  }
}
</script>
